package com.longge;

public class MaximumSwap {

    public int maximumSwap(int num) {

        String sNum = String.valueOf(num);

        char[] chars = sNum.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            if (chars[i] - '0' != 9) {
                int max = 0, index = -1;
                for (int j = i + 1; j < chars.length; j++) {
                    if (chars[j] - '0' >= max) {
                        max = chars[j] - '0';
                        index = j;
                    }
                }
                if (max > chars[i] - '0') {
                    char temp = chars[i];
                    chars[i] = chars[index];
                    chars[index] = temp;
                    break;
                }

            }
        }
        return Integer.parseInt(new String(chars));

    }

    public static void main(String[] args) {
        new MaximumSwap().maximumSwap(98368);
    }


}
